using SmartXLS;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
namespace ChartClass
{
public class clsPROD_DbSizeChart
{
private string sStartRange;
private string sEndRange;
private string sRngTotal;
public string _acct = "_($* #,##0_);_($* (#,##0);_($* \"-\"??_);_(@_)",
_noterate = "#,##0.000_);(#,##0.000);_($* \"-\"??_)",
_currency = "$#,##0.00_);($#,##0.00)",
_txt = "@",
_date = "m/d/yyyy",
_general = "General",
_generalNumber = "#,##0;(#,##0);_(* \"-\"??_)",
_intNumber = "#,##0;(#,##0);_(* \"-\"??_)",
_genNum3 = "#,##0.000;(#,##0.000);_(* \"-\"??_)",
_percent = "#,##0.00%;(#,##0.00%);_(* \"-\"??_)";
public List<ChartData> CHARTDATA { get; set; }
public string ReportingClassName { get; set; }
public bool ExcelTableFormat { get; set; }
public string CallingAppVersion { get; set; }
public int LoanCount { get; set; }
public string CallingApp { get; set; }
public string ResultType { get; set; }
public string RunNote { get; set; }
public string ConnectionString { get; set; }
public string ReportTitle { get; set; }
public string User { get; set; }
public string Version { get; set; }
public string PageNumber { get; set; }
public string ExportPathName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int SheetNumber { get; set; }
public int LastXDays { get; set; }
public string SheetName { get; set; }
#region Constructor
public clsPROD_DbSizeChart(string sConnect)
{
ConnectionString = sConnect;
// LOG = swLog;
}
#endregion Constructor
public void ProcessMe(WorkBook wb)
{
//format
//http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
// WorkBook wb;
DateTime dStart = StartDate;
DateTime dEnd = EndDate;
// string StartRange, eRange, rngTotal;
decimal nStart;
bool b = decimal.TryParse(dStart.ToString("yyyyMMdd"), out nStart);
decimal nEnd;
b = decimal.TryParse(dEnd.ToString("yyyyMMdd"), out nEnd);
//AMCSupportDataClassesDataContext dcSupport = new AMCSupportDataClassesDataContext(clsCommonStatics.GetSupportConnectionString());
#region ExcelExport
wb.NumSheets = SheetNumber + 1;
wb.setSheetName(SheetNumber, SheetName);
wb.Sheet = SheetNumber;
double nMarBot = wb.PrintBottomMargin;
double nMarTop = wb.PrintTopMargin;
double nMarRt = wb.PrintRightMargin;
double nMarLt = wb.PrintLeftMargin;
wb.PrintHeader = "";
wb.PrintFooterMargin = .25d;
wb.PrintBottomMargin = .5d;
wb.PrintTopMargin = .25d;
wb.PrintRightMargin = .25d;
wb.PrintLeftMargin = .25d;
wb.PrintGridLines = true;
wb.PrintScaleFitVPages = 2;
wb.PrintScaleFitHPages = 1;
wb.PrintScaleFitToPage = true;
wb.PrintHCenter = true;
wb.PrintTitles = "$1:$4,$C:$C"; //Not sure about the $C:$C part
wb.setPrintPaperSize((int)(8.5 * 1440), (int)(14 * 1440));
int nTopFreezeRow = 0;
int nIgnore = 0;
int nBottomFreezeRow = 4;
wb.freezePanes(nTopFreezeRow, nIgnore, nBottomFreezeRow, nIgnore, false);
wb.PrintLandscape = true;
RangeStyle rs = wb.getRangeStyle();
int nCol = 0;
int nRow = 0;
VS201300.clsSXFormatter oFrm = new VS201300.clsSXFormatter(wb);
int nLastCol = 4;
oFrm.HorizontalAlignment = RangeStyle.HorizontalAlignmentCenterAcrossCells;
oFrm.Pattern = RangeStyle.PatternSolid;// 1;
oFrm.PatternFG = Color.MidnightBlue.ToArgb();
oFrm.FontColor = Color.White;
string[] aHeader = {
"Date DownLoaded"
,"File Size"
};
oFrm.WriteText(ReportTitle, nRow, 0, nRow, aHeader.Length - 1, true, 12, false);
nRow++;
oFrm.WriteText(string.Format("Date Range: {0:d} to {1:d}", StartDate, EndDate), nRow, 0, nRow, aHeader.Length - 1, true, 10, false);
nRow++;
oFrm.WriteText(string.Format("Run Date: {0:d}", DateTime.Today), nRow, 0, nRow, aHeader.Length - 1, true, 10, false);
nRow++;
oFrm.WriteText("", nRow, 0, nRow, aHeader.Length - 1, true, 10, false);
nCol = 0;
nCol = 1;
nCol = 0;
oFrm.Wrap = true;
foreach (string s in aHeader)
{
oFrm.WriteText(s.Replace("_", " "), nRow, nCol, nRow, nCol, true, 10, true);
nCol++;
}
oFrm.Pattern = RangeStyle.PatternNull;
oFrm.FontColor = Color.Black;
oFrm.HorizontalAlignment = RangeStyle.HorizontalAlignmentLeft;
oFrm.Wrap = false;
nRow++;
nCol = 0;
int nLoanCount = 0;
int nStartRow = nRow;
int nEndRow = nRow;
var Sorted = CHARTDATA.OrderBy(r => r.Label);
int nChartStartRow = nRow;
foreach (var ln in Sorted)
{
oFrm.HorizontalAlignment = RangeStyle.HorizontalAlignmentLeft;
oFrm.WriteText(string.Format("{0}", ln.Label), nRow, nCol, nRow, nCol, false, 10, false);
wb.setColWidth(nCol, 35 * 256);
nCol++;
oFrm.WriteNumber((double)ln.Value, nRow, nCol, nRow, nCol, false, 10, _genNum3);
wb.setColWidth(nCol, 20 * 256);
nCol++;
nEndRow = nRow;
nRow++;
nCol = 0;
nLoanCount++;
}
int nChartEndRow = nEndRow + 1;
int nBottomVertRow = nRow - 1;
#endregion ExcelExport
// oFrm.WriteText("Loans displayed in red font have not been exported via the GL TRANS report. The GL TRANS needs to be generated for the date range listed for the loans in red font.", nRow, nCol, nRow, nCol, true, 10, false);
oFrm.FontColor = Color.Black;
#region UserHouseKeeping
nRow++;
nRow++;
nRow++;
VS201300.clsInfo oABt = new VS201300.clsInfo();
oFrm.WriteText(string.Format("AMC Support Version {0} Report Library Version {1}", Version, oABt.VS2103Version), nRow, 0, nRow, nLastCol, true, 8, false);
#endregion UserHouseKeeping
LoanCount = nLoanCount;
wb.Sheet = 0;
#region Chart
//create chart with it's location
//Columns & Rows
int left = 3;
int top = 6;
int right = 20;
int bottom = 40;
//create chart with it's location
ChartShape chart = wb.addChart(left, top, right, bottom);
chart.ChartType = ChartShape.Line;
string sRange = string.Format("{0}!$A${1}:$B${2}", SheetName, nStartRow, nEndRow);
chart.setLinkRange(sRange, false);
//set axis title
chart.setAxisTitle(ChartShape.XAxis, 0, "Date");
chart.setAxisTitle(ChartShape.YAxis, 0, "Gbytes");
//set series name
chart.setSeriesName(0, "File Size");
//chart.setSeriesName(1, "My Series number 2");
chart.Title = "Download File Size Chart [PROD]";
//set plot area's color to darkgray
ChartFormat chartFormat = chart.PlotFormat;
chartFormat.setSolid();
chartFormat.ForeColor = Color.DarkGray.ToArgb();
chart.PlotFormat = chartFormat;
//set series 0's color to blue
ChartFormat seriesformat = chart.getSeriesFormat(0);
chartFormat.setSolid();
seriesformat.ForeColor = Color.Red.ToArgb();
chart.setSeriesFormat(0, seriesformat);
//set series 1's color to red
//seriesformat = chart.getSeriesFormat(1);
//seriesformat.setSolid();
//seriesformat.ForeColor = Color.Red.ToArgb();
//chart.setSeriesFormat(1, seriesformat);
//set chart title's font property
ChartFormat titleformat = chart.TitleFormat;
titleformat.FontSize = 14 * 20;
titleformat.FontUnderline = true;
chart.TitleFormat = titleformat;
#endregion Chart
}
}
}